<template>
  <div class="container  order-list">
    <!-- 面包屑导航 -->
    <breadcrumb :breadcrumbConfig=breadcrumbConfig></breadcrumb>
    <!--    <breadcrumb></breadcrumb>-->
    <!-- 面包屑导航 -->

    <div class="content page-title">
      <h2>选购商品</h2>
      <div class="headerbox_right">
        <!-- <el-button size="mini" @click="back()">返回</el-button> -->
      </div>
    </div>
     <div class="basic">
      <p class="header" style="font-size:18px">基本信息</p>
      <el-form
        ref="basic"
        :inline="true"
        :model="basic"
        :rules="rulesBasic"
        label-width="80px"
      >
        <el-form-item label="收货人" prop="name">
          <el-input
            size="mini"
            v-model="basic.name"
            placeholder="请输入收货人姓名"
          ></el-input>
        </el-form-item>

        <el-form-item label="联系电话" prop="phone">
          <el-input
            size="mini"
            v-model="basic.phone"
            placeholder="请输入联系电话"
          ></el-input>
        </el-form-item>

        <!-- <el-form-item label="部门选择" prop="orgName">
          <div class="selectTree">
              <treeselect
                :options="optionsTeam"
                v-model="basic.orgName"
                search-nested
                :normalizer="normalizer"
                noResultsText="未找到"
                placeholder="请选择"
              >
              </treeselect>
            </div>
        </el-form-item> -->
         <el-form-item label="部门选择" prop="orgName">
            <el-cascader
              size="mini"
              v-model="basic.orgName"
              :options="optionsTeam"
              :props="{
                checkStrictly: true,
                label: 'orgName',
                value: 'orgCode',
                children: 'children',
              }"
              clearable
              filterable
            ></el-cascader>
          </el-form-item>
        <el-form-item label="出库类型" prop="type">
          <el-select
            size="mini"
            v-model="basic.type"
            placeholder="请选择出库类型"
            filterable
            clearable
          >
            <el-option
              v-for="items in outboundTypes"
              :key="items.id"
              :label="items.deliveryName"
              :value="items.id"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="地区" required>
          <levelAddr
            class="addressContent"
            :province="basic.province"
            :city="basic.city"
            :area="basic.area"
            @updateprovice="getAddrData"
            @updatecity="getCity"
            @updatearea="getArea"
          ></levelAddr>
        </el-form-item>

        <el-form-item label="详细地址" prop="detail">
          <div class="length">
            <el-input
              size="mini"
              v-model="basic.detail"
              placeholder="请输入详细地址"
            ></el-input>
          </div>
        </el-form-item>
      </el-form>
    </div>
    <!-- 选购商品步骤 -->
    <div class="content" v-if="stepsActive==1" style="padding:20px">
      <h3>数据筛选</h3>
      <form-filed class="search-form" :formconfig="searchFormConfig.formconfig" :formData="searchFormConfig.formData"
                  @formDataval="dialogClick" ref="formAttr"/>
    </div>

    <div class="box" v-if="stepsActive==1">
      <div class="headerTitle">商品列表</div>
      <el-tabs v-model="activeName" @tab-click="getClickTabList">
        <el-tab-pane label="选择商品" name="goods">
          <span slot="label">
        <span>选择商品({{ titleNum.totalCount ? titleNum.totalCount : 0 }})</span>
          </span>
        </el-tab-pane>
        <el-tab-pane label="选择赠品" name="second">
           <span slot="label">
        <span>选择赠品({{ titleNum.giftCount ? titleNum.giftCount : 0 }})</span>
          </span>
        </el-tab-pane>
      </el-tabs>
      <lb-table
          :column="columns"
          :data="page.list"
          pagination
          :total="page.totalNum"
          layout="total, sizes, prev, pager, next, jumper"
          :page-sizes="[5, 10, 20, 30, 50]"
          :current-page.sync="page.currentPage"
          :page-size="page.pageSize"
          @size-change="handleSizeChange"
          @p-current-change="handleCurrentChange"
          :default-sort="{prop: 'date', order: 'descending'}"
          @sort-change="handleSort"
      >
      </lb-table>
    </div>
    <!-- <div class="content" v-if="stepsActive==2">
      <div class="addressBox">
        <div class="headerTitle shopTitle">选择收货地址</div>
        <div class="addressHeader" v-if="siteDataList.length==0">
          <i class="el-icon-circle-plus-outline" style="color: #4168e7"></i>
          <el-button style="color: #4168e7;" type="text" @click="addLocation()">新增收货地址</el-button>
        </div>
      </div>
      <el-table
          :data="siteDataList"
          stripe
          style="width: 100%"
          class="site-data-list"
          :header-cell-style="{background: '#faf7fa',color:'#333333'}"
      >
        <el-table-column label="收货人" prop="userName"></el-table-column>
        <el-table-column label="手机号码" prop="phone"></el-table-column>
        <el-table-column label="地区" prop="userName">
          <template slot-scope="props">
            <p>
              {{
                props.row.provinceCode ? props.row.provinceCode +
                    props.row.cityCode +
                    props.row.regionCode : '-'
              }}
            </p>
          </template>
        </el-table-column>
        <el-table-column label="详细地址" prop="detailedAddress">
        </el-table-column>
        <el-table-column label="默认地址">
          <template slot-scope="props">
            <el-switch
                v-model="props.row.isDefault"
                :active-value="1"
                :inactive-value="0"
                @change="defaultSite(props.row.id)"
            >
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="props">
            <el-button
                type="text"
                @click="amendAddress('addressEdit')"
            >更改
            </el-button>

          </template>
        </el-table-column>
      </el-table>
    </div> -->
    <div class="orderBox">
      <div class="order">
        <p class="headerTitle shopTitle">已选商品</p>
        <!--        <el-table :data="tableData" style="width: 100%">-->
        <el-table :data="orderDetailList" style="width: 100%">
          <el-table-column min-width="200px" label="商品信息" header-align="left">
            <template slot-scope="scope">
              <div class="goodsBox" style="text-align: left">
                <div class="imgBox">
                  <!--                  <img :src="scope.row.mainImage"/>-->
                  <el-image :src="scope.row.mainImage" :preview-src-list="scope.row.mainImageArr"
                            fit="cover"></el-image>
                </div>
                <div class="goodsBox_title">
                  <h3><span>{{ scope.row.name }}</span></h3>
                  <p v-html="scope.row.specTitle"></p>
                  <p class="goods-id">商品编号：{{ scope.row.goodsNo }}</p>
                  <span v-if="scope.row.goodsType==3 || scope.row.goodsType=='赠品'" class="gift">赠品</span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="单价/数量" header-align="left" prop="quantity">
            <template slot-scope="scope">
              <div style="text-align: center" class="table-price">
                <p class="retail-price"><label>零售价：</label><el-input size="mini" v-model.number="scope.row.retailPrice" ></el-input></p>
                <p v-if="stepsActive==2" style="color: #999999">x{{ scope.row.quantity }}</p>
                <p v-if="stepsActive==1">
                  <el-input-number size="mini" v-model="scope.row.quantity" :min="1" label="描述文字"></el-input-number>
                </p>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="total" label="小计" header-align="right">
            <template slot-scope="scope">
              <!--              <p  style="text-align: right">实付￥{{ parseFloat(scope.row.total).toFixed(2) }}</p>-->
              <!-- <p style="text-align: right">实付￥{{ parseFloat(scope.row.totalRetailPrice).toFixed(2) }}</p> -->
              <p style="text-align: right">￥{{ parseFloat(scope.row.totalRetailPrice).toFixed(2) }}</p>
              <!-- <p style="text-align: right">￥{{ parseFloat(scope.row.totalMarketPrice).toFixed(2) }}</p> -->
            </template>
          </el-table-column>
          <el-table-column min-width="120px" label="操作" header-align="right" v-if="stepsActive==1">
            <template slot-scope="scope">
              <div style="text-align: right">
                <el-button type="text" @click="delectSelect(scope.$index)">移除商品</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="orderNotes">
        <div class="headerOrder">
          <div class="orderRemak">订单备注</div>
        </div>
        <div class="notes">
          <el-input
              maxlength="200"
              type="textarea"
              show-word-limit
              v-model="textarea"
              placeholder="备注"
          ></el-input>

        </div>
      </div>
      <div class="statistics">
        <p class="fourteen">
          <span>总计：共 {{ totalNumber ? totalNumber : '0' }} 件 </span>
        </p>
        <p class="fourteen">
          <span>商品总价：￥{{ totalPrice ? totalPrice : '0' }}</span>
        </p>
        <p class="fourteen">
          <span>运费￥{{ giftPrice ? giftPrice : '0' }}</span>
        </p>
        <p style="margin-right:20px">
          <span class="blue">应付:￥<span v-if="stepsActive==2">{{ dealWithNew ? dealWithNew : '0' }}</span></span>
          <span v-if="stepsActive==1">
              <el-input-number :controls="false" style="width:80px" :precision="2" size="mini" v-model="dealWithNew"
                               placeholder=""></el-input-number>
            </span>
        </p>
        <p style="margin-right:20px">
          <span v-if="stepsActive==1">
            <span class="blue">已收:￥</span>
            <span>
              <el-input-number :controls="false" @blur="handlerReceivedMoney" style="width:80px" :precision="2"
                               size="mini" v-model.trim="receivedMoney" placeholder=""></el-input-number>
            </span>
          </span>
          <span v-if="stepsActive==2">
            <span class="blue">(已收:￥<span>{{ receivedMoney ? receivedMoney : '0' }}</span>)</span>

          </span>

        </p>

      </div>
      <div class="auditRadio" v-if="stepsActive==2&&auditStatus!=-1">
        <span>是否审核:</span>
        <div>
          <el-radio-group v-model="radioForm.resource">
            <el-radio :disabled="whether" label="1">是</el-radio>
            <el-radio :disabled="whether" label="0">否</el-radio>
          </el-radio-group>
        </div>
      </div>
    </div>
    <div class="present">
      <el-button v-if="stepsActive==2" @click="cancelOrder" class="cancel-order">取消订单</el-button>
      <el-button type="primary" @click="activeSubmitType('basic')">生成订单</el-button>
    </div>
    <!--========================== el-dialog =================================-->

    <el-dialog :title="dialog.title" :visible.sync="dialog.visible" append-to-body :width="dialog.width"  :close-on-click-modal="false">
      <template v-if="dialog.type == 'moreSpecification'">
        <div v-for="(item,index) in specList " :key="index" class="skuBox">
          <div class='title'>{{ item.name }}</div>
          <div class='spec'>
            <div class='spec-item' v-for="(its,ins) in item.specItemList" :key="its.content + ins">
              <span @click="changeSpec(item.name, its.content)"
                    :class="[selectSpec[item.name] == its.content ? 'active' : '']">{{ its.content }}</span>
            </div>
          </div>
        </div>
        <div class="specificationBox">
          <p class="specificationBox_title">
            <span class="specificationBox_title_item">已选规格：</span><span class="specificationBox_title_right"><b
              v-if="matchingStr == ''">未选择</b><b v-else v-html="matchingStr"></b></span>
          </p>
          <div class="specificationBox_border">
            <div class="specificationBox_border_item">
              <span class="item">市场价</span> <span class="item">零售价</span> <span class="item">销量</span> <span
                class="item">库存</span>
            </div>
            <div class="specificationBox_border_money">
              <span class="item">{{ matching.marketPrice ? '￥' + matching.marketPrice : '-' }}</span>
              <span class="item">{{ matching.retailPrice ? '￥' + matching.retailPrice : '-' }}</span>
              <span class="item">{{ matching.soldNum || matching.soldNum === 0 ? matching.soldNum : '-' }}</span>
              <span class="item">{{ matching.stock ? matching.stock : '-' }}</span>
            </div>
          </div>
        </div>
        <div class="dialogBtnright" style="margin-top:20px" >
          <el-button class="setPay_payment_btn_quxiao" @click="handledeleteClose">取 消</el-button>
          <el-button class="setPay_payment_btn_queren" type="primary" @click="addSelectList">确 定</el-button>
        </div>
      </template>

      <!-- 支付方式 -->
      <template v-if="dialog.type == 'selectPay'">
        <el-radio-group v-model="setPay.payment" @change="selectPayment">
          <el-radio label="1">在线支付</el-radio>
        </el-radio-group>
        <div class="setPayDialogBtn">
          <div>
            <el-checkbox-group v-model="setPay.payDefault" @change="selectPayDefault">
              <el-checkbox label="1" name="type">设为默认</el-checkbox>
            </el-checkbox-group>
          </div>
          <div>
            <el-button class="setPay_payment_btn_quxiao" @click="dialog.visible = false">取 消</el-button>
            <el-button class="setPay_payment_btn_queren" type="primary" @click="confirmSelectPay">确 定</el-button>
          </div>
        </div>
      </template>
        <!-- 支付方式 -->
      <template v-if="dialog.type == 'selectPayNew'">
        <el-radio-group v-model="selectPay" @change="selectPayment">
          <el-radio v-for="(item,index) in dictionaries.order_pay_type" class="setPay_payment" :key="index" :label="item.dictId">{{item.dictName}}</el-radio>
        </el-radio-group>
        <div class="setPayDialogBtn">
          <div>
          </div>
          <div>
            <el-button class="setPay_payment_btn_quxiao" @click="dialog.visible = false;selectPay=''">取 消</el-button>
            <el-button class="setPay_payment_btn_queren" type="primary" @click="handlerSelectPay">确 定</el-button>
          </div>
        </div>
      </template>
      <!-- 在线支付 -->
      <template v-if="dialog.type == 'payMoney'">
        <div class="payMoney">
          <div>
            <p class="payMoney_should">应付:￥{{ dealWith ? dealWith : '0' }}</p>
            <p class="payMoney_already">已收:￥{{ receivedMoney ? receivedMoney : '0' }}</p>
          </div>
          <div class="payMoney_box">
            <span class="payMoney_money">支付金额</span><span class="payMoney_mo">￥</span>
            <el-input-number
                :controls="false"
                :mix="0"
                type="number"
                :precision="2"
                v-model="paymentAmount"
                style="width:110px"
            >
            </el-input-number>
          </div>
          <div class="payMoney_text">
            <span class="payMoney_text_item">总计: 共{{ totalNumber ? totalNumber : '0' }}件</span><span
              class="payMoney_text_item">商品总价: ￥{{ totalPrice ? totalPrice : '0' }}</span><span
              class="payMoney_text_item">运费: ￥{{ giftPrice ? giftPrice : '0' }}</span>
          </div>
        </div>
        <div class="dialogBtnright">
          <div>
            <el-button class="setPay_payment_btn_quxiao" @click="dialog.visible = false">取 消</el-button>
            <el-button class="setPay_payment_btn_queren" type="primary" @click="onlinePayment">确 定</el-button>
          </div>
        </div>
      </template>
    </el-dialog>

    <!--=========================== el-dialog end================================-->
  </div>

</template>

<script>
// import formFiled from '@/components/form/index'
import formFiled from '../../../../components/form/index'
// import breadcrumb from '@/components/breadcrumb'
import breadcrumb from '../../../../components/breadcrumb'
import LbTable from '../../../../components/lb-table/lb-table'
import { spawn } from 'child_process'
// import mixinsCommon from './mixins/common'
import mixinsCommon from '../../../orderBox/mixins/common'
import mixinsSKU from '../../../orderBox/mixins/mixinsSKU'
// import mixinsSKU from './mixins/mixinsSKU'
import mixinsAddModifyCommon from '../../../orderBox/mixins/mixinsAddModifyCommon'
import addressData from '@/components/addressData.js'
import Treeselect from '@riophae/vue-treeselect'
import levelAddr from '@/components/levelAddr'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'

export default {
  mixins: [mixinsCommon, mixinsSKU, mixinsAddModifyCommon],
  components: {
    formFiled,
    breadcrumb,
    LbTable,
    addressData,
    Treeselect,
    levelAddr
  },
  data () {
    return {
      outboundTypes: [],
      optionsTeam: [],
      basic: {
        name: '',
        phone: '',
        orgName: null,
        type: '',
        province: '',
        city: '',
        area: '',
        detail: '',
        textarea: ''
      }
    }
  },
  created () {
    this.initSearchCategoryList()// 初始化搜索数据 - 类目id
    this.initSearchBrandList() // 初始化搜索数据 - 品牌
    this.fetchData(0)
    // this.getPlaceGoodsCount()
    // this.selectDefAddress()// 订单地址
    // this.categoryDetails()// 查询客户基本信息
    // this.shippingAddressList()// 查询收货地址
    this.trimAddressData() // 初始化地区数据
    this.getPassFlag() // 是否必审
    this.department() // 部门数据
    this.outboundType() // 出库数据
    // this.getNumber()// 购买次数
    // this.id=this.$route.query.id;
    this.routeQuery = this.$route.query
    this.taskId = this.$route.query.taskId
    this.isChange = this.$route.query.isChange // 1为改单
    this.orderId = this.$route.query.orderId
    this.orderNo = this.$route.query.orderNo
    if (this.$route.query.payType && (this.$route.query.payType == '' || this.$route.query.payType != 1 || this.$route.query.payType != 2 || this.$route.query.payType != 3 || this.$route.query.payType == null)) {
      this.$nextTick(() => {
        this.selectPay = '1'
      })
    }
    console.log(this.selectPay, 'payType')

    if (this.$route.query.userId) {
      this.customerId = this.$route.query.userId
    }
    // else if (this.$route.query.type == 1) {
    //   console.log('内部出库')
    // }
    //  else {
    //   this.open()
    // }
    this.addressId = this.$route.query.addressId
    this.pingZ = this.$route.query.pingZ
    if (this.$route.query.channelOrderId) {
      this.channelOrderId = this.$route.query.channelOrderId
    }

    if (!this.is_null(this.pingZ)) {
      this.pingZ = true
    }
    this.voucher = JSON.parse(sessionStorage.getItem('voucher'))
    if (!this.is_null(this.voucher)) {
      this.textarea = this.voucher.note
      this.fileList = this.voucher.fileImg
    }

    if (this.$route.query.orderCommodityList) {
      // 判断是否是路由传参
      this.tableData = this.$route.query.orderCommodityList
      for (const item of this.tableData) {
        item.title = item.name
        item.sellPrice = item.price
      }
      this.tableZp = this.$route.query.orderComplimentaryList
    } else {
      this.tableData = JSON.parse(sessionStorage.getItem('goodsList'))
      this.tableZp = JSON.parse(sessionStorage.getItem('giftList'))
    }

    if (!this.is_null(this.tableData)) {
      // this.tableData不为空，就执行计算
      for (let i = 0; i < this.tableData.length; i++) {
        this.arry.push(this.tableData[i].id)
      }
      for (let i = 0; i < this.tableZp.length; i++) {
        this.arrayZp.push(this.tableZp[i].id)
      }
      // this.calculation()
      this.receivedMoney = this.$route.query.receivedMoney
      this.total = this.$route.query.total
    } else {
      // if (!this.$route.query) {
      this.tableData = []
      // this.tableZp = []
      // }
    }
    this.brandSelectBox()
    this.brandSelect()
    // this.getDefaultAddress();
    document.onkeydown = (e) => {
      const key = window.event.keyCode
      if (key == 13) {
        this.searchGoods()
      }
    }
  },
  watch: {},
  computed: {},
  methods: {
    getAddrData (val) {
      this.basic.province = val
      this.basic.city = ''
      this.basic.area = ''
    },
    getCity (val) {
      this.basic.city = val
      this.basic.area = ''
    },
    getArea (val) {
      this.basic.area = val
    },
    outboundType () {
      this.axios
        .post(
          'order/v1/internal/delivery/config/list',
          {
            request: {
              deliveryName: '',
              orgCode: sessionStorage.getItem('orgCode'),
              pageNo: 1,
              pageSize: 999
            }
          },
          {
            headers: {
              isLoading: false
            }
          }
        )
        .then((res) => {
          if (res.code == 0) {
            this.outboundTypes = res.data.list
          } else {
            this.$message.error(res.message)
          }
        })
    },
    normalizer (node) {
      return {
        id: node.orgCode,
        label: node.orgName,
        children: node.children
      }
    },
    // 第一层新增收货地址
    addLocation () {
      this.dialog.type = 'addLocation'
      this.dialog.title = '新增地址'
      this.dialog.visible = true
      this.dialog.width = '450px'
      this.form.userName = ''
      this.form.phone = ''
      this.form.detailedAddress = ''
      this.form.addressValue = ''
      this.form.isDefault = 0
      this.form.provinceCode = ''
      this.form.cityCode = ''
      this.form.regionCode = ''
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    // 接受表单组件的数据
    dialogClick (val) {
      this.searchFormVal = Object.assign({}, val)
      this.fetchData()
    },
    cancelOrder () {
      this.stepsActive = 1
    },
    // 新增收货地址
    addAddress (type, row) {
      if (this.dialog.type == 'addressAmend') {
        this.dialog.visible = false
        this.dialog.type = 'addAddress'
        this.dialog.title = '新增地址'
        this.dialog.visible = true
        this.dialog.width = '450px'
        this.form.userName = ''
        this.form.phone = ''
        this.form.detailedAddress = ''
        this.form.addressValue = ''
        this.form.isDefault = 0
        this.form.provinceCode = ''
        this.form.cityCode = ''
        this.form.regionCode = ''
        this.$nextTick(() => {
          this.$refs['form'].clearValidate()
        })
      }
    },
    // 地区修改
    onChangeAddress (val) {
      const addressOptions = this.addressOptions
      for (let i = 0; i < val.length; i++) {
        if (i === 0) {
          this.form.provinceCode = addressOptions[val[0]].label
          continue
        }
        if (i === 1) {
          this.form.cityCode = addressOptions[val[0]].children[val[1]].label
          continue
        }
        if (i === 2) {
          this.form.regionCode = addressOptions[val[0]].children[val[1]].children[val[2]].label
          continue
        }
      }
    },
    // 部门选择列表
    department () {
      this.axios
        .post(
          '/sys/v1/org/tree/select',
          {
            request: {
              orgName: '',
              orgType: ''
            },
            version: ''
          },
          {
            headers: {
              isLoading: false
            }
          }
        )
        .then((res) => {
          if (res.code == 0) {
            this.optionsTeam = res.data
          } else {
            this.$message.error(res.message)
          }
        })
    },
    // 修改收货地址弹框列表里面的使用地址
    employ (row) {
      this.siteDataList = []
      // this.$set(this.siteDataList, 'siteDataList', row)
      this.siteDataList.push(row)
      this.dialog.visible = false
      // const data = {
      //   id: 1, //	订单物流id	body	true	integer(int64)
      //   postAddress: row.provinceCode + row.cityCode + row.regionCode + row.detailedAddress, //	收货地址	body	true	string
      //   postCityCode: row.cityCode, //	收货市级code	body	true	string
      //   postContact: row.phone, //	收货人联系方式	body	true	string
      //   postDetailedAddress: row.detailedAddress, //	收货详细地址	body	true	string
      //   postName: row.userName, //	收货人	body	true	string
      //   postProvinceCode: row.provinceCode, //	收货省级code	body	true	string
      //   postRegionCode: row.regionCode //	收货区级code	body	true	string
      // }
      // this.$api.updateOrderAddress(data).then((res) => {
      //   if (res.code == 0) {
      //     this.$message.success('使用成功！')
      //     this.dialog.visible = false
      //   }
      // }).catch((err) => {
      //   console.log(err)
      // })
    },
    // 初始化地区数据
    trimAddressData () {
      const arr = []
      for (const province in addressData) {
        const childrenCity = []
        for (const city in addressData[province]) {
          const childrenArea = []
          addressData[province][city].forEach((e, i) => {
            childrenArea.push({ title: '市区', label: e, value: i })
          })
          childrenCity.push({ title: '城市', label: city, children: childrenArea, value: city })
        }
        arr.push({ title: '省份', label: province, children: childrenCity, value: province })
      }
      // 修改 value 值
      arr.forEach((e, i) => {
        e.value = i
        e.children.forEach((ee, ii) => {
          ee.value = ii
        })
      })
      this.addressOptions = arr
    },
    // 订单地址列表数据
    selectDefAddress () {
      this.siteDataList = []
      const userId = this.$route.query.userId
      // const userId = 1
      const params = { userId }
      this.$api.selectDefAddress(params).then((res) => {
        if (res.code === 0 && res.data) {
          if (this.siteDataList.length == 0) {
            this.$nextTick(() => {
              this.siteDataList.push(res.data)
            })
          }
          this.$forceUpdate()
        }
      }).catch(err => {
        console.log(err)
      })
    },

    // 关闭弹框
    handledeleteClose () {
      this.dialog.visible = false
    },
    // 下单-选购商品数量统计查询接口
    getPlaceGoodsCount (params) {
      // const params = {}
      this.$api.getPlaceGoodsCount(params).then((res) => {
        if (res.code === 0) {
          this.titleNum = res.data
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    // 显示  dialog
    showDialogshowDialog (title, type, row) {
      this.dialog.type = type
      this.currentRow = row
    },
    getClickTabList (tab) {
      this.tabIndex = tab.index
      this.fetchData(tab.index)
    },
    is_null (content) {
      if (content) {
        return false
      } else {
        return true
      }
    },
    reset () {
      this.goods = {
        name: '',
        brand: '',
        category: [],
        code: ''
      }
      this.currentPageZp = 1
      this.pageSizeZp = 10
      this.currentPage1 = 1
      this.pageSizegoods = 10
      this.fetchData()
      this.giftList()
    },
    searchGoods () {
      this.currentPage1 = 1
      this.pageSizegoods = 10
      this.fetchData()
    },
    searhgift () {
      this.currentPageZp = 1
      this.pageSizeZp = 10
      this.giftList()
    },

    //* * 品牌下拉 **//
    brandSelectBox () {
      this.axios
        .get('/order/comm/commodity/selectList', {
          headers: {
            isLoading: false
          }
        })
        .then((res) => {
          if (res.code == 0) {
            this.brandselect = res.data
          } else {
            this.$message.error(res.message)
          }
        })
    },
    //* * 品牌下拉 **//
    // 分类下拉框
    brandSelect () {
      this.axios
        .get('/order/comm/commodity/selectBrand', {
          headers: {
            isLoading: false
          }
        })
        .then((res) => {
          if (res.code == 0) {
            this.options = res.data
          } else {
            this.$message.error(res.message)
          }
        })
    },
    handleChange (currentValue, lodValue, row) {
      // const quantity = item.quantity
      this.$nextTick(() => {
        setTimeout(() => {
          row.quantity = Number(currentValue)
        }, 10)
      })

      // this.$set(item, 'quantity', quantity)
      // this.$set(item, 'totalRetailPrice', item.quantity * Number(item.retailPrice))
      // this.$set(item, 'totalMarketPrice', item.quantity * Number(item.marketPrice))
      // item.totalRetailPrice = item.quantity * Number(item.retailPrice)
      // item.totalMarketPrice = item.quantity * Number(item.marketPrice)
      // this.uprice = item.marketPrice
    },
    handleChangeZp (val) {
      this.currentPageZp = val
      this.giftList()
    },
    handleSizeChangeZp (val) {
      this.pageSizeZp = val
      this.giftList()
    },
    // 数量文本框值改变
    changeCount (row, index) {
      if (
        row.number == null ||
          row.number == '' ||
          (row.number != 'number' && isNaN(row.number))
      ) {
        row.number = 1
      } else if (row.number <= 1) {
        row.number = 1
        this.$message({
          message: '已经减到最低了哦',
          type: 'warning'
        })
      }
      this.$set(this.tableData, index, {
        createdTime: row.createdTime,
        id: row.id,
        number: row.number,
        sellPrice: row.sellPrice,
        specificationName: row.specificationName,
        title: row.title,
        total: parseFloat(row.number * row.sellPrice).toFixed(2),
        brandId: row.brandId,
        typeId: row.typeId
      })
      this.tableData[index].number = row.number
      // this.calculation()
    },
    /** 修改商品的单价**/
    changePrice (row, index) {
      if (!this.is_null(row.sellPrice)) {
        this.$set(this.tableData, index, {
          createdTime: row.createdTime,
          id: row.id,
          number: row.number,
          sellPrice: row.sellPrice,
          specificationName: row.specificationName,
          title: row.title,
          total: parseFloat(Number(row.number) * Number(row.sellPrice)).toFixed(
            2
          ),
          brandId: row.brandId,
          typeId: row.typeId
        })
      } else {
        this.$message.warning('单价不能为空')
      }
      // this.calculation()
    },
    // 删除
    delectRow (index) {
      this.tableData.splice(index, 1)
      this.arry.splice(index, 1)
      // this.calculation()
    },
    notesEvent () {
      const notes = {
        note: this.textarea,
        fileImg: this.fileList
      }
      sessionStorage.setItem('voucher', JSON.stringify(notes))
    },
    // 选择支付方式弹框内的设置默认
    selectPayDefault (e) {
      if (this.setPay.payment) {
        if (e == true) {
          localStorage.setItem('Payment', 1)
          localStorage.setItem('PayDefault', true)
        } else {
          localStorage.removeItem('Payment')
          localStorage.removeItem('PayDefault')
        }
      }
    },
    // 选择支付方式
    selectPayment (e) {
      if (e == 1) { // 在线支付
        this.payStatus = e
      }
    },
    // 支付方式确定
    onlinePayment () {
      const data = {
        orderId: this.orderId,
        receivedAmount: this.paymentAmount
      }
      this.$api.onlinePay(data).then(res => {
        if (res.code == 0) {
          // this.$message.success('操作成功！')
          this.dialog.visible = false
          this.$notify({
            title: '成功',
            message: '操作成功 ！',
            type: 'success'
          })
        }
      })
    },
    // 生成收款码确定弹框
    confirmSelectPay () {
      if (this.dialog.type == 'selectPay') {
        this.dialog.visible = false
        if (this.setPay.payment != 1) {
          this.$message.warning('请选择支付方式！')
        }
        if (this.setPay.payment == 1) { // 1表示在线支付
          this.dialog.type = 'payMoney'
          this.dialog.visible = true
          this.dialog.title = '在线支付'
          this.dialog.width = '640px'
          this.paymentAmount = 0.00
        }
      }
    }
  }
}
</script>

<style scoped lang="scss">
  .setPay_payment{
    display: block;
    margin-bottom: 15px;
    margin-left: 25px
  }
  .basic {
  background: #fff;
  padding: 20px;
  margin-bottom: 10px;
  /deep/.el-cascader .el-input .el-input__inner {
    width: 400px;
  }
}
.selectTree {
  width: 250px;
  display: inline-block;
  vertical-align: middle;
  margin-right: 10px;
}
/deep/.vue-treeselect {
  height: 28px;
}
/deep/.vue-treeselect--searchable .vue-treeselect__input-container {
  height: 28px;
  line-height: 28px;
  width: 100%;
}
/deep/.vue-treeselect__single-value {
  font-size: 14px;
  line-height: 28px;
}
/deep/.vue-treeselect__menu-container {
  font-size: 15px;
}
/deep/.vue-treeselect__multi-value-item {
  height: 20px;
  line-height: 20px;
  padding: 0;
}
/deep/.vue-treeselect__input {
  height: 26px;
  line-height: 26px;
  outline: none;
  border: none;
  padding: 0;
}
/deep/.vue-treeselect__placeholder {
  font-size: 10px;
  line-height: 28px;
}
/deep/.vue-treeselect--has-value .vue-treeselect__multi-value {
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/deep/.vue-treeselect__control {
  height: 28px;
}
// @import './assets/addModifyCommon';
@import '../../../orderBox/assets/addModifyCommon.scss';
</style>
